/*
 * Copyright 2008. Mount Sinai Hospital, Toronto, Canada.
 * 
 * Licensed under the Apache License, Version 2.0. You
 * can find a copy of the license at:
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * IN NO EVENT SHALL MOUNT SINAI HOSPITAL BE LIABLE TO ANY PARTY FOR DIRECT, 
 * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST 
 * PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, 
 * EVEN IF MOUNT SINAI HOSPITAL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
 * DAMAGE.
 * 
 * MOUNT SINAI HOSPITAL SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND 
 * ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". 
 * MOUNT SINAI HOSPITAL HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 
 * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 
 */

package com.sinai.mshab.widgets;

import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;

/**
 * Useful {@link HorizontalPanel} which can be placed inside tabs. Supports
 * images (icons).
 * 
 * @author serge
 * 
 */
public class TabContents extends HorizontalPanel {

	private static int width = 100;
	private static int height = 40;
	private int index;

	/**
	 * Creates a text tab content.
	 * 
	 * @param text
	 *            the text to appear in the tab.
	 * @param index
	 *            optionally provide an index of this tab
	 */
	public TabContents(String text, int index) {
		this.index = index;
		setUpSimple(text);
	}

	/**
	 * Creates a text tab content.
	 * 
	 * @param text
	 *            the text to appear in the tab.
	 */
	public TabContents(String text) {
		setUpSimple(text);
	}

	private void setUpSimple(String text) {
		setStyleName("mshab-TabContents");
		setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		add(new Label(text));
		setWidth(width + "px");
		setHeight(height + "px");
	}

	/**
	 * Creates a new tab content with an image icon
	 * 
	 * @param image_url
	 *            the url of the icon of the tab
	 * @param text
	 *            the text to appear in the tab.
	 * @param index
	 *            optionally provide an index of this tab
	 */
	public TabContents(String text, String image_url, int index) {
		this.index = index;
		setUpWithImage(text, image_url);
	}

	/**
	 * Creates a new tab content with an image icon
	 * 
	 * @param image_url
	 *            the url of the icon of the tab
	 * @param text
	 *            the text to appear in the tab.
	 */
	public TabContents(String text, String image_url) {
		setUpWithImage(text, image_url);
	}

	private void setUpWithImage(String text, String image_url) {
		setStyleName("mshab-TabContents");
		setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		add(new Image(image_url));
		add(new Label(text));
		setWidth(width + "px");
		setHeight(height + "px");
	}

	/**
	 * @param width
	 *            the width to set
	 */
	public static void setWidth(int width) {
		TabContents.width = width;
	}

	/**
	 * @return the width
	 */
	public static int getWidth() {
		return width;
	}

	/**
	 * @param height
	 *            the height to set
	 */
	public static void setHeight(int height) {
		TabContents.height = height;
	}

	/**
	 * @return the height
	 */
	public static int getHeight() {
		return height;
	}

	/**
	 * @return Returns the index of the tab
	 */
	public int getIndex() {
		return index;
	}
	
	public void hide() {
		this.setVisible(false);
	}
	
	public void show() {
		this.setVisible(true);
	}
}
